﻿using System;
using System.Collections.Generic;
using System.Text;
using Stonecode.Solar.ParticleEngine.Emitters;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Stonecode.Solar.ParticleEngine;

namespace Stonecode.Solar.ParticleEffectEditor.Serialization
{
    public struct OutputSettings
    {
        public string TextureName;
        public string TextureFullName;
        public string EmitterName;
        public bool Enabled;
        public EmitterType EmitterType;
        public uint MaxParticles;
        public float ParticlesPerSecond;
        public TimeSpan Duration;
        public float DurationRandomness;
        public float EmitterVelocitySensitivity;
        public float MinHorizontalVelocity;
        public float MaxHorizontalVelocity;
        public float MinVerticalVelocity;
        public float MaxVerticalVelocity;
        public Vector3 Gravity;
        public float EndVelocity;
        public Color MinColor;
        public Color MaxColor;
        public float MinRotateSpeed;
        public float MaxRotateSpeed;
        public float MinStartSize;
        public float MaxStartSize;
        public float MinEndSize;
        public float MaxEndSize;
        public EmitterTypeSettings EmitterTypeSettings;
        public Vector3 Offset;

        // Color Blend Options

        public Blend ColorSourceBlend;
        public Blend ColorDestinationBlend;
        public BlendFunction ColorBlendFunction;

        // Alpha blending settings.
        public Blend AlphaSourceBlend;
        public Blend AlphaDestinationBlend;
        public BlendFunction AlphaBlendFunction;
        // Overall Blending
        public Color BlendFactor;

        public void AssignSettings(EmitterSettings s, EmitterTypeSettings ets, Emitter e)
        {
            TextureName = s.TextureName;
            EmitterName = e.EmitterName;
            Enabled = e.Enabled;
            EmitterType = ets.EmitterType;
            MaxParticles = s.MaxParticles;
            ParticlesPerSecond = s.ParticlesPerSecond;
            Duration = s.Duration;
            DurationRandomness = s.DurationRandomness;
            EmitterVelocitySensitivity = s.EmitterVelocitySensitivity;
            MinHorizontalVelocity = s.MinHorizontalVelocity;
            MaxHorizontalVelocity = s.MaxHorizontalVelocity;
            MinVerticalVelocity = s.MinVerticalVelocity;
            MaxVerticalVelocity = s.MaxVerticalVelocity;
            Gravity = s.Gravity;
            EndVelocity = s.EndVelocity;
            MinColor = s.MinColor;
            MaxColor = s.MaxColor;
            MinRotateSpeed = s.MinRotateSpeed;
            MaxRotateSpeed = s.MaxRotateSpeed;
            MinStartSize = s.MinStartSize;
            MaxStartSize = s.MaxStartSize;
            MinEndSize = s.MinEndSize;
            MaxEndSize = s.MaxEndSize;
            //SourceBlend = s.SourceBlend;
            //DestinationBlend = s.DestinationBlend;
            //AlphaBlendOperation = s.AlphaBlendOperation;
            //BlendOperation = s.BlendOperation;
            //AlphaFunction = s.AlphaFunction;
            EmitterTypeSettings = ets;

            AlphaSourceBlend = s.AlphaSourceBlend;
            AlphaDestinationBlend = s.AlphaDestinationBlend;
            AlphaBlendFunction = s.AlphaBlendFunction;

            BlendFactor = s.BlendFactor;

            ColorBlendFunction = s.ColorBlendFunction;
            ColorDestinationBlend = s.ColorDestinationBlend;
            ColorSourceBlend = s.ColorSourceBlend;

            Offset = s.Offset;
             
        }
        public void ConvertToEmitterSettings(out EmitterSettings s, out EmitterTypeSettings ets)
        {
            s = new EmitterSettings(MaxParticles);
            s.TextureName = TextureName;
            //switch (EmitterType)
            //{
            //    case EmitterType.Circle: ets = new CircleEmitterTypeSettings(0, false); break;
            //    case EmitterType.Line: ets = new LineEmitterTypeSettings(0, 0, false); break;
            //    case EmitterType.Point: ets = new EmitterTypeSettings(EmitterType.Point); break;
            //    case EmitterType.Rectangle: ets = new RectangleEmitterTypeSettings(new RectangleF(), 0, false); break;
            //}
            
            ets = EmitterTypeSettings;
            s.ParticlesPerSecond = ParticlesPerSecond;
            s.Duration = Duration;
            s.DurationRandomness = DurationRandomness;
            s.EmitterVelocitySensitivity = EmitterVelocitySensitivity;
            s.MinHorizontalVelocity = MinHorizontalVelocity;
            s.MaxHorizontalVelocity = MaxHorizontalVelocity;
            s.MinVerticalVelocity = MinVerticalVelocity;
            s.MaxVerticalVelocity = MaxVerticalVelocity;
            s.Gravity = Gravity;
            s.EndVelocity = EndVelocity;
            s.MinColor = MinColor;
            s.MaxColor = MaxColor;
            s.MinRotateSpeed = MinRotateSpeed;
            s.MaxRotateSpeed = MaxRotateSpeed;
            s.MinStartSize = MinStartSize;
            s.MaxStartSize = MaxStartSize;
            s.MinEndSize = MinEndSize;
            s.MaxEndSize = MaxEndSize;
            s.Enabled = Enabled;
            
            s.AlphaSourceBlend = AlphaSourceBlend;
            s.AlphaDestinationBlend = AlphaDestinationBlend;
            s.AlphaBlendFunction = AlphaBlendFunction;

            s.BlendFactor = BlendFactor;

            s.ColorBlendFunction = ColorBlendFunction;
            s.ColorDestinationBlend = ColorDestinationBlend;
            s.ColorSourceBlend = ColorSourceBlend;

            s.Offset = Offset;
        }
    }

    
}
